/**
 * @author Philipp Hannemann & Christoph Lehnert
 */

package org.bonn.ooka.core;

import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class CommandLine {

	private boolean m_useConsole = false;
	private Console m_console = null;
	private BufferedReader m_reader = null;

	public CommandLine(InputStream istr) {
		if (System.console() != null) {
			this.m_console = System.console();
			this.m_useConsole = true;
		} else {
			this.m_reader = new BufferedReader(new InputStreamReader(istr));
			this.m_useConsole = false;
		}
	}

	public String readline() {
		if (this.m_useConsole) {
			return this.m_console.readLine();
		} 
		else {
			try {
				return this.m_reader.readLine();
			} catch (IOException e) {
			}
		}
		return "";
	}

}
